//
//  VideoData.m
//  BosidengIphone
//
//  Created by  on 11-12-31.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "VideoData.h"
#import "AppDelegate.h"

@implementation VideoData

@synthesize videoID;
@synthesize title;
@synthesize stort;
@synthesize videoUrl;
@synthesize image;
@synthesize modifyDate;

- (id)init {
    if (self = [super init]) {
        ;
    }
    return self;
}

- (void)dealloc {
    [videoID release];
    [title release];
    [stort release];
    [videoUrl release];
    [image release];
    [modifyDate release];
    [super dealloc];
}

- (void)setValue:(NSDictionary *)data {
    [super setValue:data];
    self.videoID = [data objectForKey:@"VideoID"];
    self.title = [data objectForKey:@"Title"];
    self.stort = [data objectForKey:@"Stort"];
    self.videoUrl = [data objectForKey:@"VideoUrl"];
    self.image = [data objectForKey:@"Image"];
    self.modifyDate = [data objectForKey:@"ModifyDate"];
}

- (void)removeLocalImages {
    //删除本地数据包括图片
    NSString *imagePath = [AppDelegate getCacheFilePathByUrl:image];
    [AppDelegate deleteFile:imagePath];
}

+ (NSString *)getAllItemsQueryString {
    NSString *query = [NSString stringWithFormat:@"WHERE language='%@' ORDER BY stort", [AppDelegate getLanguage]];
    return query;
}

+ (id)getItemByID:(NSString *)uid {
    return [VideoData findFirstByCriteria:[VideoData getItemQueryString:@"video_i_d" value:uid]];
}

+ (NSArray *)getAllItems {
    return [VideoData findByCriteria:[VideoData getAllItemsQueryString]];
}

@end
